#!/bin/bash

prompt()
{
    echo "$*"
    read A
    [ "$A" == "y" ] && return 1
    return 0
}

echo Press enter to execute commands ending in ...
echo

prompt "    0. Cleaning" up ./self ...
mkdir -p self | exit 1
rm -rf self/*

prompt "    1. Copying" lexer to self...
cp  scanner/lexer self
[ -e scanner/inc ] && cp -r scanner/inc self

prompt "    2." Run "(in ./self)" ../tmp/bin/binary on lexer
cd self && ../tmp/bin/binary -S ../skeletons lexer
cd ..

prompt "    3." Copy the generated scannerbase.h and lex.cc to ./scanner
cp ./self/lex.cc ./self/scannerbase.h ./scanner


prompt "    4. Rebuild: rebuilding the program ('build program')"
touch ./scanner/a
build program || exit 1
echo

prompt "    5. Again: run '../tmp/bin/binary' on lexer"
cd self && ../tmp/bin/binary -S ../skeletons lexer
cd ..

echo "    6. Diffs should show differences in timestamps only:"
for file in scannerbase.h lex.cc
do
    prompt "       RUN: 'diff self/$file scanner' ..."
    diff self/$file scanner
    echo
done

# prompt "    7. No differences in called rules should be observed:"
# diff self/pre-rules self/post-rules
# 
# prompt "    8. [optional] recreate the scanner without -R"
# cd self && ../tmp/bin/binary -S ../skeletons lexer
# cp lex.cc scannerbase.h ../scanner
# cd ..
# touch scanner/a
# build program












